<?php 
defined('RUN_KATANA') or die('Restricted access');
if($adc->getCurrentAd())
{
	unset($buttons);
	$katana->setAction('editor_ad');
	$i = 0;
	
	$i++;
	$buttons[$i]['title'] = ucfirst($txt->getWord('save'));
	$buttons[$i]['params']['class'] = 'btn btn-primary bold';
	$buttons[$i]['params']['tag'] = 'button';
	$buttons[$i]['params']['type'] = 'submit';
	$buttons[$i]['params']['icon'] = $theme->getIconSetPrefix().'-save';
	
	if($adc->getCurrentAd()->getIsValid())
	{
		$i++;
		$buttons[$i]['title'] = ucfirst($txt->getWord('preview', $words));
		$buttons[$i]['params']['id'] = 'preview-button';
		$buttons[$i]['params']['class'] = 'btn btn-default bold command';
		$buttons[$i]['params']['onmousedown'] = '$(\'#preview\').val(1);';
		$buttons[$i]['params']['onclick'] = '$(\'#'.$com->getId().'_editor_ad\').submit();';
		$buttons[$i]['params']['tag'] = 'button';
		$buttons[$i]['params']['icon'] = $theme->getIconSetPrefix().'-camera';
	}
	
	$i++;
	if($adc->getCurrentAd()->getIsCompleted() > 0)
	{
		if(($adc->getCurrentAd()->getIsPaid() > 0) && ($adc->getCurrentAd()->getIsValid()))
		{ 
			$buttons[$i]['title'] = ucfirst($txt->getWord('publish', $words).' '.$txt->getWord('again', $words));
			$buttons[$i]['href'] = '/c/'.$com->getComId().'?list=ad&activate='.$adc->getCurrentAd()->getId().'';
			$buttons[$i]['onclick'] = '';
			$buttons[$i]['params']['class'] = 'btn btn-default bold';
			$buttons[$i]['params']['icon'] = $theme->getIconSetPrefix().'-repeat';
		}
	}
	else
	{
		if($adc->getCurrentAd()->getActive() > 0)
		{ 
			$buttons[$i]['title'] = ucfirst($txt->getWord('set_as').' '.$adc->getCurrentAd()->getIsBoughtText());
			$buttons[$i]['href'] = '/c/'.$com->getComId().'?list=ad&complete='.$adc->getCurrentAd()->getId().'';
			$buttons[$i]['onclick'] = '';
			$buttons[$i]['params']['class'] = 'btn btn-default bold';
			$buttons[$i]['params']['icon'] = $theme->getIconSetPrefix().'-check';
		}
		else
		{ 
			if($adc->getCurrentAd()->getIsPaid() > 0)
			{
				if($adc->getCurrentAd()->getIsValid())
				{
					$buttons[$i]['title'] = ucfirst($txt->getWord('publish', $words));
					$buttons[$i]['href'] = '/c/'.$com->getComId().'?list=ad&activate='.$adc->getCurrentAd()->getId().'';
					$buttons[$i]['onclick'] = '';
					$buttons[$i]['params']['class'] = 'btn btn-success bold';
					$buttons[$i]['params']['icon'] = $theme->getIconSetPrefix().'-play';
				}
			}
			else
			{ 
				if($adc->getCurrentAd()->getIsValid())
				{
					$buttons[$i]['title'] = ucfirst($txt->getWord('proceed_to_payement', $words)).' >>';
					$buttons[$i]['href'] = '/c/'.$com->getComId().'?edit=payment&ad='.$adc->getCurrentAd()->getId().'';
					$buttons[$i]['onclick'] = '';
					$buttons[$i]['params']['class'] = 'btn btn-default bold';
					$buttons[$i]['params']['icon'] = $theme->getIconSetPrefix().'-credit-card';
				}
			}
		}
	}
	$com->setButtonsContent($buttons);
	
	$com->setButtonsFooter(false);
	$fullSpan = 4;
	?>
	
	<form id="<?php echo $com->Id; ?>_editor_ad" action="<?php echo $katana->getFormAction().'ad='.$adc->getCurrentAdId(); ?>" method="post" enctype="multipart/form-data" name="editor_ad" role="form">
		<?php if($_GET['display'] == 'renew'): ?>
		<?php require('renew.php'); ?>
		<?php else: ?> 
			<?php if($_GET['view'] != 'images'): ?>
            	<div class="row-fluid row">
                	<div class="span6 col-md-6 col-sm-6 col-xs-6">
                    	<div class="panel panel-primary">
                            <div class="panel-heading">
                            	<h3 class="panel-title"><?php echo ucfirst($txt->getWord('placement')); ?></h3>
                            </div>
                            <div class="panel-body">
								<?php echo $controller->getForm('editor_ad_cat')->getFieldsHTML(); ?>
                                <?php if($adc->getCurrentAd()->getUsePrice()): ?>
                                <div id="editor_ad_price_fields" <?php if($adc->getCurrentAd()->getPriceDisplay() == 0) { echo 'style="display:none;"'; } ?>>
                                	<div class="row">
                                     	<div class="col-md-4">
										<?php echo $controller->getForm('editor_ad_price')->Fields['PriceCurrency']->getHTML(); ?>
                                        </div>
                                        <div class="col-md-4">
                                        <?php echo $controller->getForm('editor_ad_price')->Fields['PriceLocal']->getHTML(); ?>
                                        </div>
                                    	<div class="col-md-4 <?php if($adc->getSetting('UseCurrencies') > 0) { echo 'hidden'; } ?>">
                                        <?php echo $controller->getForm('editor_ad_price')->Fields['PriceGlobal']->getHTML(); ?>
                                        </div>
                                    </div>
                                </div><div class="clearfix"></div>
                                <div class="row">
                                	<div class="col-md-6">
                                		<?php if($adc->getCurrentAd()->getIsBuying() == 0): ?>
										<?php echo $controller->getForm('editor_ad_price')->Fields['PriceDisplay']->getHTML(); ?>
                                        <?php endif; ?>
                                    </div>
                                    <div class="col-md-6">
                                    	<button class="btn btn-primary btn-block" type="submit" name="submit" value="submit"><?php echo ucfirst($txt->getWord('save')); ?></button>
                                    </div>
                                </div>
                                <div class="clearfix"></div>
                                <?php endif; ?>
                                <?php echo $controller->getForm('editor_ad_publish')->getFieldsHTML(); ?>
                            </div>
                        </div>
                    </div>
                    <div class="span6 col-md-6 col-sm-6 col-xs-6">
                    	<div class="panel panel-primary">
                            <div class="panel-heading">
                            	<h3 class="panel-title"><?php echo ucfirst($txt->getWord('ad_information')); ?></h3>
                            </div>
                            <div class="panel-body"><?php echo $controller->getForm('editor_ad')->getFieldsHTML(); ?></div>
                        </div>
                    </div>
                </div>
				<?php 
                $formCat = $controller->getForm('editor_form_ad_type_cat');
                if(count($formCat->getFields()) > 0)
                {
                    $formCat->setColumns($adc->getSetting('FormCatCols')); ?>
                    <div class="panel panel-info">
                        <div class="panel-heading">
                            <h3 class="panel-title"><?php echo ucfirst($txt->getWord('additional_information')); ?></h3>
                        </div>
                        <div class="panel-body" id="additional-fields"><?php echo $formCat->getFormBsHTML(); ?></div>
                    </div>
                <?php 
                }
                ?>
                <div class="row-fluid row">
                	<div class="span4 col-md-4">
                    	<div class="panel panel-info">
                            <div class="panel-heading">
                                <h3 class="panel-title"><?php echo ucfirst($txt->getWord('contact_information')); ?></h3>
                            </div>
                            <div class="panel-body" id="editor_ad_contact"><?php echo $controller->getForm('editor_ad_contact')->getFieldsHTML(); ?></div>
                        </div>
                    </div>
                    <div class="span4 col-md-4">
                        <div class="panel panel-info">
                            <div class="panel-heading">
                                <h3 class="panel-title"><?php 
                                    if(ucfirst($txt->getWord('sale_location_'.$adc->getCurrentAd()->getTypeId())) != 'Sale_location_'.$adc->getCurrentAd()->getTypeId())
                                    { echo ucfirst($txt->getWord('sale_location_'.$adc->getCurrentAd()->getTypeId())); }
                                    else
                                    { echo ucfirst($txt->getWord('sale_location')); }
                                ?></h3>
                            </div>
                            <div class="panel-body" id="editor_ad_location"><?php echo $controller->getForm('editor_ad_location')->getFieldsHTML(); ?></div>
                        </div>
                    </div>
                    <div class="span4 col-md-4">
                    	<div class="panel panel-info">
                            <div class="panel-heading">
                                <h3 class="panel-title"><?php echo ucfirst($txt->getWord(array('map', 'location'))); ?></h3>
                            </div>
                            <div class="panel-body" id="editor_ad_map"><?php require('map.php'); ?></div>
                        </div>
                    </div>
                </div>
				<?php echo getButtonsHTML($theme->HFBSets[$theme->ComHFB]['button'], $com->getButtonsContent()); ?>
				<br clear="all" /><hr />
				<div class="command-bar"><?php echo getButtonsHTML($theme->HFBSets[$theme->ComHFB]['button'], $com->getButtonsContent()); ?></div>
			<?php endif; ?>
            <div class="panel panel-info">
                <div class="panel-heading">
                    <h3 class="panel-title"><?php echo ucfirst($txt->getWord('upload').' '.$txt->getWord('images')); ?></h3>
                </div>
                <div class="panel-body" id="upload-images"><?php require('editor-images-multiple-upload.php');  ?></div>
            </div>
            <div class="panel panel-info">
                <div class="panel-heading">
                    <h3 class="panel-title"><?php echo ucfirst($txt->getWord('images')); ?></legend></h3>
                </div>
                <div class="panel-body" id="editor-images"><?php require('editor-images.php');  ?></div>
            </div>
			<?php if(($adc->getSetting('UserLevelAdDoc') > 0) && ($user->getPartnerStatus() >= $adc->getSetting('UserLevelAdDoc'))): ?>
			<table class="com_form" cellpadding="0" border="0" cellspacing="0">
				<tr>
					<td class="form_right vtop" valign="top" id="upload-images">
						<legend>
							<?php echo ucfirst($txt->getWord('upload').' '.$txt->getWord('files')); ?>
							 - (<?php echo ucfirst($txt->getWord('documents').' '.$txt->getWord('and').' '.$txt->getWord('brochures')); ?>)
						</legend><br />
						<?php require('editor-files-upload.php');  ?>
					</td>
				</tr>
				<tr>
					<td class="form_left vtop" valign="top" id="editor-files">
						<legend><?php echo ucfirst($txt->getWord('files')); ?></legend><br />
						<p></p>
						<?php require('editor-files.php');  ?>
					</td>
				</tr>
				<tr><td><hr /></td></tr>
			</table><br clear="all" />
			<?php endif; ?>
		<?php endif; ?>
		
		<input id="<?php echo $com->Id; ?>_editor_ad_stealth" type="hidden" name="stealth_<?php echo md5(date("m-d-w")); ?>" value="" />
		<input type="hidden" name="action" value="<?php echo $katana->getAction(); ?>" /> 
		<input type="hidden" name="ad" value="<?php echo $adc->getCurrentAdId(); ?>" />
		<input id="preview" type="hidden" name="preview" value="0" /> 
	</form>
<?php 
}
?>